package com.xiaoxin.nmzp.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaoxin.nmzp.server.entity.domain.SysUser;
import com.xiaoxin.nmzp.server.entity.req.UpdateUserReq;
import com.xiaoxin.nmzp.server.mapper.SysUserMapper;
import com.xiaoxin.nmzp.server.service.SysUserService;
import com.xiaoxin.nmzp.utils.JwtUtil;
import com.xiaoxin.nmzp.utils.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author xiaoxin
 * @description 针对表【sys_user(用户信息表)】的数据库操作Service实现
 * @createDate 2024-10-17 14:02:46
 */
@Service("NmzpSysUserService")
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser>
        implements SysUserService {

    /**
     * 更新用户头像
     *
     * @param userName
     * @param avatar
     * @return
     */
    @Override
    public boolean updateUserAvatar(String userName, String avatar) {
        LambdaUpdateWrapper<SysUser> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(SysUser::getUserName, userName);
        updateWrapper.set(SysUser::getAvatar, avatar);
        return baseMapper.update(updateWrapper) > 0;
    }

    /**
     * 更新用户信息
     *
     * @param updateUserReq
     */
    @Override
    public void updateUser(UpdateUserReq updateUserReq) {
        LambdaUpdateWrapper<SysUser> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(SysUser::getUserId, UserUtils.get().getUserId());
        updateWrapper.set(SysUser::getNickName, updateUserReq.getNickName());
        updateWrapper.set(SysUser::getSex, updateUserReq.getSex());
        updateWrapper.set(SysUser::getBirthday, updateUserReq.getBirthday());
        baseMapper.update(updateWrapper);
    }
}




